﻿using InParkRedemptionAPI.DataAccess;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using RapidSalesAdminPortalAPI.DataAccess;
using WebAPI.Common;
using WebAPI.Common.Attributes;
using WebAPI.DataAccess;
using WebAPI.Models;
using WebAPI.Util;

namespace WebAPI.Controllers
{
    //[Authorize]
    //[Route("api/[controller]")]
    //[ApiController]
    //public class DataDictionaryController : ParentController
    //{
    //    private readonly RS_AdmPortalContext _context;
    //    private readonly IConfiguration _configuration;
    //    private readonly ILogUtility _logUtility;
    //    private readonly ILogger _logger;
    //    private readonly IDataProtectorUtility _dataProtectorUntility;
    //    //private readonly IPaginationService _paginationService;

    //    public DataDictionaryController(RS_AdmPortalContext context, IConfiguration configuration, ILogUtility logUtility, 
    //        ILogger<DataDictionaryController> logger, IDataProtectorUtility dataProtectorUntility)//, IPaginationService paginationService
    //    {
    //        _context = context;
    //        _configuration = configuration;
    //        _logUtility = logUtility; // sample code for DI of common utility class
    //        _logger = logger;
    //        _dataProtectorUntility = dataProtectorUntility;
    //        //_paginationService = paginationService;
    //    }

    //    /// <summary>
    //    /// EF Core 分页Demo
    //    /// </summary>
    //    /// <param name="page"></param>
    //    /// <returns></returns>
    //    //[HttpGet("GetDataDictionaryPagedList/{page}")]
    //    //public async Task<OffsetPaginationResult<FrIpDataDictionary>> GetFrIpDataDictionaryPagedList(int page)
    //    //{
    //    //    var query = _context.FrIpDataDictionaries.Where(x => x.Enable).OrderByDescending(x => x.CreateDate);
    //    //    return await _paginationService.OffsetPaginateAsync(query, new OffsetQueryModel() { 
    //    //        Page = page, //指定要返回第几页INse
    //    //        Size = 5 //指定每页记录条数
    //    //    });
    //    //}

    //    [HttpPost("GetDataDictionaryList")]
    //    public async Task<ActionResult<ResultMsg>> GetDataDictionaryList([FromBody] GetDataDictionaryListRequest requestModel)
    //    {
    //        var resultMsg = new ResultMsg();
    //        try
    //        {
    //            IQueryable<FrIpDataDictionary> paComont = _context.FrIpDataDictionaries
    //                //.Where(x=>(!x.CodeItemName.Equals("Basic") && !x.ItemTypeName.Equals("Operation Area")) && (!x.CodeItemName.Equals("RedemptionPoint") && !x.ItemTypeName.Equals("Products")))
    //                .AsQueryable();


    //            if (!string.IsNullOrWhiteSpace(requestModel.Enable))
    //                paComont = _context.FrIpDataDictionaries.Where(x => x.Enable.ToString() == requestModel.Enable);

    //            if (!string.IsNullOrWhiteSpace(requestModel.CodeItemId))
    //                paComont = paComont.Where(x => x.CodeItemId.Contains(requestModel.CodeItemId));

    //            if (!string.IsNullOrWhiteSpace(requestModel.CodeItemName))
    //                paComont = paComont.Where(x => x.CodeItemName.Contains(requestModel.CodeItemName));

    //            if (!string.IsNullOrWhiteSpace(requestModel.ItemTypeId))
    //                paComont = paComont.Where(x => x.ItemTypeId.Contains(requestModel.ItemTypeId));

    //            if (!string.IsNullOrWhiteSpace(requestModel.ItemTypeName))
    //                paComont = paComont.Where(x => x.ItemTypeName.Contains(requestModel.ItemTypeName));

    //            if (!string.IsNullOrWhiteSpace(requestModel.Description))
    //                paComont = paComont.Where(x => x.Description.Contains(requestModel.Description));

    //            if (!string.IsNullOrWhiteSpace(requestModel.DefaultSetValue))
    //                paComont = paComont.Where(x => x.DefaultSetValue.Contains(requestModel.DefaultSetValue));

    //            var paData = paComont.ToList()?.Select(x => new GetDataDictionaryListResponse()
    //            {
    //                Id = x.Id,
    //                CodeItemId = x.CodeItemId,
    //                CodeItemName = x.CodeItemName,
    //                ItemTypeId = x.ItemTypeId,
    //                ItemTypeName = x.ItemTypeName,
    //                DefaultSetValue = x.DefaultSetValue,
    //                Description = x.Description,
    //                Enable = x.Enable,
    //                CreateDate = x.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"),
    //                UpdateDate = x.UpdateDate.ToString("yyyy-MM-dd HH:mm:ss"),
    //                CreateUser = UserNameQuery(x.CreateUser),
    //                UpdateUser = UserNameQuery(x.UpdateUser)
    //            }).AsQueryable();

    //            if (!string.IsNullOrWhiteSpace(requestModel.Field) && paComont.Count() > 0)
    //                paData = DBHelper.DataSorting(paData, requestModel.Field, requestModel.Order);
    //            else
    //                paData = DBHelper.DataSorting(paData, "CreateDate", "desc");

    //            var dataDicList = await BasePageOutputExtensions.ToPagedListAsync(paData.ToList(), requestModel.Page, requestModel.PageSize);

            
    //            return resultMsg.SetResultMsg(
    //                 (int)ResultCode.Success,
    //                 HelperUtility.GetDescription(ResultCode.Success),
    //                 dataDicList);
    //        }
    //        catch (Exception ex)
    //        {
    //            _logger.LogError(ex.Message);
    //            return resultMsg.SetResultMsg(
    //                 (int)ResultCode.NoDataFound,
    //                 HelperUtility.GetDescription(ResultCode.NoDataFound),
    //                 null);
    //        }
    //    }

    //    [HttpPost("GetDataDictionaryListExceptBasic")]
    //    public async Task<ActionResult<ResultMsg>> GetDataDictionaryListExceptBasic([FromBody] GetDataDictionaryListRequest requestModel)
    //    {
    //        var resultMsg = new ResultMsg();
    //        try
    //        {
    //            IQueryable<FrIpDataDictionary> paComont = _context.FrIpDataDictionaries.Where(x => x.CodeItemName != "Basic" && x.ItemTypeName != "Products").AsQueryable();

    //            if (!string.IsNullOrWhiteSpace(requestModel.Enable))
    //                paComont = _context.FrIpDataDictionaries.Where(x => x.Enable.ToString() == requestModel.Enable);

    //            if (!string.IsNullOrWhiteSpace(requestModel.CodeItemId))
    //                paComont = paComont.Where(x => x.CodeItemId.Contains(requestModel.CodeItemId));

    //            if (!string.IsNullOrWhiteSpace(requestModel.CodeItemName))
    //                paComont = paComont.Where(x => x.CodeItemName.Contains(requestModel.CodeItemName));

    //            if (!string.IsNullOrWhiteSpace(requestModel.ItemTypeId))
    //                paComont = paComont.Where(x => x.ItemTypeId.Contains(requestModel.ItemTypeId));

    //            if (!string.IsNullOrWhiteSpace(requestModel.ItemTypeName))
    //                paComont = paComont.Where(x => x.ItemTypeName.Contains(requestModel.ItemTypeName));

    //            if (!string.IsNullOrWhiteSpace(requestModel.Description))
    //                paComont = paComont.Where(x => x.Description.Contains(requestModel.Description));

    //            if (!string.IsNullOrWhiteSpace(requestModel.DefaultSetValue))
    //                paComont = paComont.Where(x => x.DefaultSetValue.Contains(requestModel.DefaultSetValue));

    //            var paData = paComont.ToList()?.Select(x => new GetDataDictionaryListResponse()
    //            {
    //                Id = x.Id,
    //                CodeItemId = x.CodeItemId,
    //                CodeItemName = x.CodeItemName,
    //                ItemTypeId = x.ItemTypeId,
    //                ItemTypeName = x.ItemTypeName,
    //                DefaultSetValue = x.DefaultSetValue,
    //                Description = x.Description,
    //                Enable = x.Enable,
    //                CreateDate = x.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"),
    //                UpdateDate = x.UpdateDate.ToString("yyyy-MM-dd HH:mm:ss"),
    //                CreateUser = UserNameQuery(x.CreateUser),
    //                UpdateUser = UserNameQuery(x.UpdateUser)
    //            }).AsQueryable();

    //            if (!string.IsNullOrWhiteSpace(requestModel.Field) && paComont.Count() > 0)
    //                paData = DBHelper.DataSorting(paData, requestModel.Field, requestModel.Order);
    //            else
    //                paData = DBHelper.DataSorting(paData, "CreateDate", "desc");

    //            var dataDicList = await BasePageOutputExtensions.ToPagedListAsync(paData.ToList(), requestModel.Page, requestModel.PageSize);

    //            return resultMsg.SetResultMsg(
    //                 (int)ResultCode.Success,
    //                 HelperUtility.GetDescription(ResultCode.Success),
    //                 dataDicList);
    //        }
    //        catch (Exception ex)
    //        {
    //            _logger.LogError(ex.Message);
    //            return resultMsg.SetResultMsg(
    //                 (int)ResultCode.NoDataFound,
    //                 HelperUtility.GetDescription(ResultCode.NoDataFound),
    //                 null);
    //        }
    //    }

    //    [HttpPost("DataDictionaryList")]
    //    public async Task<ActionResult<ResultMsg>> DataDictionaryList([FromBody] DataDictionaryListRequest requestModel)
    //    {
    //        var resultMsg = new ResultMsg();
    //        try
    //        {
    //            IQueryable<FrIpDataDictionary> paComont = _context.FrIpDataDictionaries.Where(x => x.Enable).AsQueryable();

    //            if (!string.IsNullOrWhiteSpace(requestModel.CodeItemName))
    //                paComont = paComont.Where(x => x.CodeItemName.Equals(requestModel.CodeItemName));

    //            if (!string.IsNullOrWhiteSpace(requestModel.ItemTypeName))
    //                paComont = paComont.Where(x => x.ItemTypeName.Equals(requestModel.ItemTypeName));

    //            var paData = paComont.ToList()?.Select(x => new DataDictionaryListResponse()
    //            {
    //                Id = x.Id,
    //                DefaultSetValue = x.DefaultSetValue
                    
    //            }).OrderBy(x=>x.DefaultSetValue).ToList();


    //            return resultMsg.SetResultMsg(
    //                 (int)ResultCode.Success,
    //                 HelperUtility.GetDescription(ResultCode.Success),
    //                 paData);
    //        }
    //        catch (Exception ex)
    //        {
    //            _logger.LogError(ex.Message);
    //            return resultMsg.SetResultMsg(
    //                 (int)ResultCode.NoDataFound,
    //                 HelperUtility.GetDescription(ResultCode.NoDataFound),
    //                 null);
    //        }
    //    }

    //    [HttpGet("{id}")]
    //    public async Task<ActionResult<ResultMsg>> GetFrIpDataDictionary(Guid id)
    //    {
    //        var resultMsg = new ResultMsg();
    //        var dataDictionary = await _context.FrIpDataDictionaries.FindAsync(id);

    //        if (dataDictionary == null)
    //        {
    //            return resultMsg.SetResultMsg(
    //            (int)ResultCode.NotFound,
    //            HelperUtility.GetDescription(ResultCode.Success),
    //            null);
    //        }

    //        return resultMsg.SetResultMsg(
    //            (int)ResultCode.Success,
    //            HelperUtility.GetDescription(ResultCode.Success),
    //            new GetDataDictionaryListResponse(){
    //                Id = dataDictionary.Id,
    //                CodeItemId = dataDictionary.CodeItemId,
    //                CodeItemName = dataDictionary.CodeItemName,
    //                ItemTypeId = dataDictionary.ItemTypeId,
    //                ItemTypeName = dataDictionary.ItemTypeName,
    //                DefaultSetValue = dataDictionary.DefaultSetValue,
    //                Description = dataDictionary.Description,
    //                Enable = dataDictionary.Enable,
    //                CreateDate = dataDictionary.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"),
    //                UpdateDate = dataDictionary.UpdateDate.ToString("yyyy-MM-dd HH:mm:ss"),
    //                CreateUser = UserNameQuery(dataDictionary.CreateUser),
    //                UpdateUser = UserNameQuery(dataDictionary.UpdateUser)
    //        });
    //    }

    //    [HttpDelete("{id}")]
    //    public async Task<ActionResult<ResultMsg>> DeleteFrIpDataDictionary(Guid id)
    //    {
    //        var resultMsg = new ResultMsg();
    //        try
    //        {
    //            var FrIpDataDictionary = await _context.FrIpDataDictionaries.FindAsync(id);

    //            if (FrIpDataDictionary == null)
    //            {
    //                return resultMsg.SetResultMsg(
    //                (int)ResultCode.NotFound,
    //                HelperUtility.GetDescription(ResultCode.NotFound),
    //                null);
    //            }
    //            _context.Entry(FrIpDataDictionary).State = EntityState.Deleted;
    //            _context.SaveChanges();
    //            return resultMsg.SetResultMsg(
    //                (int)ResultCode.Success,
    //                HelperUtility.GetDescription(ResultCode.Success),
    //                null);
    //        }
    //        catch (DbUpdateException ex)
    //        {
    //            return resultMsg.SetResultMsg(
    //             (int)ResultCode.ErrorOnRequestUnMarshalling,
    //             "The delete statement conflicted with the reference constraint",
    //             null);
    //        }
    //        catch (Exception ex)
    //        {
    //            return resultMsg.SetResultMsg(
    //             (int)ResultCode.ErrorOnRequestUnMarshalling,
    //              HelperUtility.GetDescription(ResultCode.ErrorOnRequestUnMarshalling),
    //             null);
    //        }
    //    }

    //    [Log("DataDictionary", "InsertFrIpDataDictionary", description: "DataDictionary/InsertFrIpDataDictionary", LogType: Enums.LogType.AdministratorAccountLog)]
    //    [HttpPost("InsertFrIpDataDictionary")]

    //    public async Task<ActionResult<ResultMsg>> InsertFrIpDataDictionary([FromBody] InsertFrIpDataDictionaryRequest requestModel)
    //    {
    //        var resultMsg = new ResultMsg();
    //        try
    //        {
    //            if (FrIpDataDictionaryExistByKey(requestModel.CodeItemName,  requestModel.ItemTypeName)) {
    //                return resultMsg.SetResultMsg(
    //               (int)ResultCode.ConfigurationAlreadyExists,
    //               HelperUtility.GetDescription(ResultCode.ConfigurationAlreadyExists),
    //               null);
    //            }

    //            FrIpDataDictionary dataDictory = new FrIpDataDictionary();
    //            dataDictory.Id = Guid.NewGuid();
    //            dataDictory.CodeItemId = requestModel.CodeItemId;
    //            dataDictory.CodeItemName = requestModel.CodeItemName;
    //            dataDictory.ItemTypeId = requestModel.ItemTypeId;
    //            dataDictory.ItemTypeName = requestModel.ItemTypeName;
    //            dataDictory.DefaultSetValue = requestModel.DefaultSetValue;
    //            dataDictory.Description = requestModel.Description;
    //            dataDictory.Enable = requestModel.Enable;
    //            dataDictory.CreateDate = DateTime.Now;
    //            dataDictory.UpdateDate = DateTime.Now;
    //            dataDictory.CreateUser = CurrentUserId;
    //            dataDictory.UpdateUser = CurrentUserId;

    //            _context.FrIpDataDictionaries.Add(dataDictory);
    //            await _context.SaveChangesAsync();

    //            return resultMsg.SetResultMsg(
    //            (int)ResultCode.Success,
    //            HelperUtility.GetDescription(ResultCode.Success),
    //            null);
    //        }
    //        catch (DbUpdateConcurrencyException ex)
    //        {
    //            return resultMsg.SetResultMsg(
    //             (int)ResultCode.ErrorOnRequestUnMarshalling,
    //             HelperUtility.GetDescription(ResultCode.ErrorOnRequestUnMarshalling),
    //             null);
    //        }
    //    }

    //    // PUT: api/FrIpDataDictionary/2a0ef56c-3785-4138-a330-005730d42e21
    //    // To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
    //    [Log("DataDictionary", "UpdateFrIpDataDictionary", description: "DataDictionary/UpdateFrIpDataDictionary", LogType: Enums.LogType.AdministratorAccountLog)]
    //    [HttpPut("UpdateFrIpDataDictionary")]
    //    public async Task<ActionResult<ResultMsg>> UpdateFrIpDataDictionary([FromBody] UpdateFrIpDataDictionaryRequest requestModel)
    //    {
    //        var resultMsg = new ResultMsg();
    //        try
    //        {
    //            if (!FrIpDataDictionaryExists(requestModel.Id))
    //            {
    //                return resultMsg.SetResultMsg(
    //                 (int)ResultCode.NoDataToBeSavedAreFoundInRequest,
    //                 HelperUtility.GetDescription(ResultCode.UserNotFound),
    //                 null);
    //            }

    //            FrIpDataDictionary dataDictory = await _context.FrIpDataDictionaries.FirstOrDefaultAsync(x => x.Id == requestModel.Id);
    //            dataDictory.CodeItemId = requestModel.CodeItemId;
    //            dataDictory.CodeItemName = requestModel.CodeItemName;
    //            dataDictory.ItemTypeId = requestModel.ItemTypeId;
    //            dataDictory.ItemTypeName = requestModel.ItemTypeName;
    //            dataDictory.DefaultSetValue = requestModel.DefaultSetValue;
    //            dataDictory.Description = requestModel.Description;
    //            dataDictory.Enable = requestModel.Enable;
    //            _context.Entry(dataDictory).State = EntityState.Modified;
    //            await _context.SaveChangesAsync();

    //            return resultMsg.SetResultMsg(
    //            (int)ResultCode.Success,
    //            HelperUtility.GetDescription(ResultCode.Success),
    //            null);
    //        }
    //        catch (Exception ex)
    //        {
    //            _logger.LogError("UpdateFrIpDataDictionary:"+ ex.Message);
    //            return resultMsg.SetResultMsg(
    //             (int)ResultCode.ErrorOnRequestUnMarshalling,
    //             HelperUtility.GetDescription(ResultCode.UserNotFound),
    //             null);
    //        }
    //    }

    //    [Log("DataDictionary", "EnableFrIpDataDictionary", description: "DataDictionary/EnableFrIpDataDictionary", LogType: Enums.LogType.AdministratorAccountLog)]
    //    [HttpPut("EnableFrIpDataDictionary")]
    //    public async Task<ActionResult<ResultMsg>> EnableFrIpDataDictionary([FromBody] EnableFrIpDataDictionaryRequest requestModel)
    //    {
    //        ResultMsg resultMsg = new();
    //        var dataDicList = _context.FrIpDataDictionaries.Where(x => requestModel.ids.Contains(x.Id.ToString())).ToList();
    //        if (dataDicList == null || dataDicList.Count <= 0)
    //        {
    //            return resultMsg.SetResultMsg(
    //           (int)ResultCode.NoDataFound,
    //           HelperUtility.GetDescription(ResultCode.NoDataFound),
    //           null);
    //        }
    //        foreach (var dataDic in dataDicList)
    //        {
    //            dataDic.Enable = requestModel.enable;
    //        }
    //        await _context.SaveChangesAsync();
    //        return resultMsg.SetResultMsg(
    //            (int)ResultCode.Success,
    //            HelperUtility.GetDescription(ResultCode.Success),
    //            null);
    //    }


    //    [Log("DataDictionary", "InsertBasicOperationArea", description: "DataDictionary/InsertBasicOperationArea", LogType: Enums.LogType.AdministratorAccountLog)]
    //    [HttpPost("InsertBasicOperationArea")]

    //    public async Task<ActionResult<ResultMsg>> InsertBasicOperationArea([FromBody] InsertFrIpDataDictionaryRequest requestModel)
    //    {
    //        var resultMsg = new ResultMsg();
    //        try
    //        {
    //            if (FrIpDataDictionaryExist("Option Set Group", "Operation Area", requestModel.DefaultSetValue))
    //            {
    //                return resultMsg.SetResultMsg(
    //               (int)ResultCode.ConfigurationAlreadyExists,
    //               HelperUtility.GetDescription(ResultCode.ConfigurationAlreadyExists),
    //               null);
    //            }

    //            var model = GetFrIpDataDictionary("Option Set Group", "Operation Area");

    //            if (model == null) {
    //                return resultMsg.SetResultMsg(
    //              (int)ResultCode.ConfigurationNotExists,
    //              HelperUtility.GetDescription(ResultCode.ConfigurationNotExists),
    //              null);
    //            }

    //            FrIpDataDictionary dataDictory = new FrIpDataDictionary();
    //            dataDictory.Id = Guid.NewGuid();
    //            dataDictory.CodeItemId = model.CodeItemId;
    //            dataDictory.CodeItemName = model.CodeItemName;
    //            dataDictory.ItemTypeId = model.ItemTypeId;
    //            dataDictory.ItemTypeName = model.ItemTypeName;
    //            dataDictory.DefaultSetValue = requestModel.DefaultSetValue;
    //            dataDictory.Description = requestModel.Description;
    //            dataDictory.Enable = requestModel.Enable;
    //            dataDictory.CreateDate = DateTime.Now;
    //            dataDictory.UpdateDate = DateTime.Now;
    //            dataDictory.CreateUser = CurrentUserId;
    //            dataDictory.UpdateUser = CurrentUserId;

    //            _context.FrIpDataDictionaries.Add(dataDictory);
    //            await _context.SaveChangesAsync();

    //            return resultMsg.SetResultMsg(
    //            (int)ResultCode.Success,
    //            HelperUtility.GetDescription(ResultCode.Success),
    //            null);
    //        }
    //        catch (DbUpdateConcurrencyException ex)
    //        {
    //            return resultMsg.SetResultMsg(
    //             (int)ResultCode.ErrorOnRequestUnMarshalling,
    //             HelperUtility.GetDescription(ResultCode.ErrorOnRequestUnMarshalling),
    //             null);
    //        }
    //    }


    //    [Log("DataDictionary", "UpdateBasicOperationArea", description: "DataDictionary/UpdateBasicOperationArea", LogType: Enums.LogType.AdministratorAccountLog)]
    //    [HttpPut("UpdateBasicOperationArea")]
    //    public async Task<ActionResult<ResultMsg>> UpdateBasicOperationArea([FromBody] UpdateFrIpDataDictionaryRequest requestModel)
    //    {
    //        var resultMsg = new ResultMsg();
    //        try
    //        {
    //            if (!FrIpDataDictionaryExists(requestModel.Id))
    //            {
    //                return resultMsg.SetResultMsg(
    //                 (int)ResultCode.NoDataToBeSavedAreFoundInRequest,
    //                 HelperUtility.GetDescription(ResultCode.NoDataToBeSavedAreFoundInRequest),
    //                 null);
    //            }


    //            var model = GetFrIpDataDictionary("Option Set Group", "Operation Area", requestModel.DefaultSetValue);
    //            if (FrIpDataDictionaryExist("Option Set Group", "Operation Area", requestModel.DefaultSetValue)
    //             && model != null && model.Id != requestModel.Id)
    //            {
    //                return resultMsg.SetResultMsg(
    //               (int)ResultCode.ConfigurationAlreadyExists,
    //               HelperUtility.GetDescription(ResultCode.ConfigurationAlreadyExists),
    //               null);
    //            }


    //            FrIpDataDictionary dataDictory = await _context.FrIpDataDictionaries.FirstOrDefaultAsync(x => x.Id == requestModel.Id);
    //            dataDictory.DefaultSetValue = requestModel.DefaultSetValue;
    //            dataDictory.Description = requestModel.Description;
    //            dataDictory.Enable = requestModel.Enable;
    //            _context.Entry(dataDictory).State = EntityState.Modified;
    //            await _context.SaveChangesAsync();

    //            return resultMsg.SetResultMsg(
    //            (int)ResultCode.Success,
    //            HelperUtility.GetDescription(ResultCode.Success),
    //            null);
    //        }
    //        catch (Exception ex)
    //        {
    //            _logger.LogError("UpdateBasicOperationArea:" + ex.Message);
    //            return resultMsg.SetResultMsg(
    //             (int)ResultCode.ErrorOnRequestUnMarshalling,
    //             HelperUtility.GetDescription(ResultCode.ErrorOnRequestUnMarshalling),
    //             null);
    //        }
    //    }


    //    [Log("DataDictionary", "InsertRedemptionProduct", description: "DataDictionary/InsertRedemptionProduct", LogType: Enums.LogType.AdministratorAccountLog)]
    //    [HttpPost("InsertRedemptionProduct")]

    //    public async Task<ActionResult<ResultMsg>> InsertRedemptionProduct([FromBody] InsertFrIpDataDictionaryRequest requestModel)
    //    {
    //        var resultMsg = new ResultMsg();
    //        try
    //        {
    //            if (FrIpDataDictionaryExist("RedemptionPoint", "Products", requestModel.DefaultSetValue))
    //            {
    //                return resultMsg.SetResultMsg(
    //               (int)ResultCode.ConfigurationAlreadyExists,
    //               HelperUtility.GetDescription(ResultCode.ConfigurationAlreadyExists),
    //               null);
    //            }

    //            var model = GetFrIpDataDictionary("RedemptionPoint", "Products");

    //            if (model == null)
    //            {
    //                return resultMsg.SetResultMsg(
    //              (int)ResultCode.ConfigurationNotExists,
    //              HelperUtility.GetDescription(ResultCode.ConfigurationNotExists),
    //              null);
    //            }

    //            FrIpDataDictionary dataDictory = new FrIpDataDictionary();
    //            dataDictory.Id = Guid.NewGuid();
    //            dataDictory.CodeItemId = model.CodeItemId;
    //            dataDictory.CodeItemName = model.CodeItemName;
    //            dataDictory.ItemTypeId = model.ItemTypeId;
    //            dataDictory.ItemTypeName = model.ItemTypeName;
    //            dataDictory.DefaultSetValue = requestModel.DefaultSetValue;
    //            dataDictory.Description = requestModel.Description;
    //            dataDictory.Enable = requestModel.Enable;
    //            dataDictory.CreateDate = DateTime.Now;
    //            dataDictory.UpdateDate = DateTime.Now;
    //            dataDictory.CreateUser = CurrentUserId;
    //            dataDictory.UpdateUser = CurrentUserId;

    //            _context.FrIpDataDictionaries.Add(dataDictory);
    //            await _context.SaveChangesAsync();

    //            return resultMsg.SetResultMsg(
    //            (int)ResultCode.Success,
    //            HelperUtility.GetDescription(ResultCode.Success),
    //            null);
    //        }
    //        catch (DbUpdateConcurrencyException ex)
    //        {
    //            return resultMsg.SetResultMsg(
    //             (int)ResultCode.ErrorOnRequestUnMarshalling,
    //             HelperUtility.GetDescription(ResultCode.ErrorOnRequestUnMarshalling),
    //             null);
    //        }
    //    }


    //    [Log("DataDictionary", "UpdateRedemptionProduct", description: "DataDictionary/UpdateRedemptionProduct", LogType: Enums.LogType.AdministratorAccountLog)]
    //    [HttpPut("UpdateRedemptionProduct")]
    //    public async Task<ActionResult<ResultMsg>> UpdateRedemptionProduct([FromBody] UpdateFrIpDataDictionaryRequest requestModel)
    //    {
    //        var resultMsg = new ResultMsg();
    //        try
    //        {
    //            if (!FrIpDataDictionaryExists(requestModel.Id))
    //            {
    //                return resultMsg.SetResultMsg(
    //                 (int)ResultCode.NoDataToBeSavedAreFoundInRequest,
    //                 HelperUtility.GetDescription(ResultCode.NoDataToBeSavedAreFoundInRequest),
    //                 null);
    //            }

    //            var model = GetFrIpDataDictionary("RedemptionPoint", "Products", requestModel.DefaultSetValue);
    //            if (FrIpDataDictionaryExist("RedemptionPoint", "Products", requestModel.DefaultSetValue)
    //                && model != null && model.Id != requestModel.Id)
    //            {
    //                return resultMsg.SetResultMsg(
    //               (int)ResultCode.ConfigurationAlreadyExists,
    //               HelperUtility.GetDescription(ResultCode.ConfigurationAlreadyExists),
    //               null);
    //            }

    //            FrIpDataDictionary dataDictory = await _context.FrIpDataDictionaries.FirstOrDefaultAsync(x => x.Id == requestModel.Id);
    //            dataDictory.DefaultSetValue = requestModel.DefaultSetValue;
    //            dataDictory.Description = requestModel.Description;
    //            dataDictory.Enable = requestModel.Enable;
    //            _context.Entry(dataDictory).State = EntityState.Modified;
    //            await _context.SaveChangesAsync();

    //            return resultMsg.SetResultMsg(
    //            (int)ResultCode.Success,
    //            HelperUtility.GetDescription(ResultCode.Success),
    //            null);
    //        }
    //        catch (Exception ex)
    //        {
    //            _logger.LogError("UpdateRedemptionProduct:" + ex.Message);
    //            return resultMsg.SetResultMsg(
    //             (int)ResultCode.ErrorOnRequestUnMarshalling,
    //             HelperUtility.GetDescription(ResultCode.ErrorOnRequestUnMarshalling),
    //             null);
    //        }
    //    }


    //    [NonAction]
    //    private bool FrIpDataDictionaryExists(Guid id)
    //    {
    //        return _context.FrIpDataDictionaries.Any(e => e.Id == id);
    //    }

    //    [NonAction]
    //    private FrIpDataDictionary GetFrIpDataDictionary(string codeItemName, string itemTypeName)
    //    {
    //        return _context.FrIpDataDictionaries?.FirstOrDefault(e => e.CodeItemName == codeItemName && e.ItemTypeName == itemTypeName);
    //    }


    //    [NonAction]
    //    private bool FrIpDataDictionaryExist(string codeItemName, string itemTypeName, string DefaultSetValue)
    //    {
    //        return _context.FrIpDataDictionaries.Any(e => e.CodeItemName == codeItemName &&  e.ItemTypeName == itemTypeName && e.DefaultSetValue == DefaultSetValue);
    //    }

    //    [NonAction]
    //    private bool FrIpDataDictionaryExistByKey(string codeItemName, string itemTypeName)
    //    {
    //        return _context.FrIpDataDictionaries.Any(e => e.CodeItemName == codeItemName && e.ItemTypeName == itemTypeName);
    //    }

    //    [NonAction]
    //    private FrIpDataDictionary GetFrIpDataDictionary(string codeItemName, string itemTypeName, string DefaultSetValue)
    //    {
    //        return _context.FrIpDataDictionaries.FirstOrDefault(e => e.CodeItemName == codeItemName && e.ItemTypeName == itemTypeName && e.DefaultSetValue == DefaultSetValue);
    //    }



    //    [NonAction]
    //    private string UserNameQuery(Guid id)
    //    {
    //        FrIpAdministratorAccount dt = _context.FrIpAdministratorAccounts?.FirstOrDefault(x => x.Id.Equals(id));
    //        return dt?.AccountName ?? "";
    //    }

    //}
}
